use base64::{Engine as _, engine::general_purpose};

#[derive(Debug)]
pub struct Credential {
    username: String,
    password: String,
}

/// 生成用于身份验证的credit
/// 其中`password`一般为登录的授权码，并非邮箱密码
/// # Example
/// ```
/// let credit = Credential::new("name", "ABCDEFG");
/// ```
impl Credential {
    pub fn new(username: &str, password: &str) -> Credential {
        Credential {
            username: username.to_string(),
            password: password.to_string(),
        }
    }
    ///获取账号密码的base64编码值
    pub fn base64(&self) -> (String, String) {
        //标准base64编码，使用STANDARD_NO_PAD服务器会无法识别
        let b_name = general_purpose::STANDARD.encode(self.username.as_bytes()) + "\r\n";
        let b_pswd = general_purpose::STANDARD.encode(self.password.as_bytes()) + "\r\n";
        (b_name, b_pswd)
    }
}